import {
    getadphone,
    dybbAd
} from '../../../api/app'
import user from '../../../utils/user'
Page({
    data: {
        phonelist: [],
        isnull: false,
    },
    onLoad: function (options) {
        getadphone().then((res) => {
            console.log(res, 'yfsudahiygiuyh');
            if (res.length === 0) {
                this.setData({
                    isnull: true,
                    phonelist: [{
                        name: '刘峰',
                        phone: '17177788882'
                    }]
                })
                
            } else {
                this.data.phonelist = res.map((ele, index) => {
                    return {
                        name: ele.salesName,
                        phone: ele.phone
                    }
                })
            }
        })
    },
    onShow() {
        user.waitLogin().then(() => {
            this.dybbAdfn(0, 1, 0)
        })
    },
    dybbAdfn(isClick, isExposure, isPhone) {
        dybbAd({
            isClick: isClick,
            isExposure: isExposure,
            isPhone: isPhone,
            companyName: user.companyName,
            phone: user.phoneNum,
            type:0,
        }).then((res) => {
            console.log(res, 'fgasgyfjiusagygyasu');
        })
    },
    callPhone1(phoneNumber) {
        wx.makePhoneCall({
            phoneNumber: phoneNumber,
            success: (res) => {
                console.log(111, res);
            },
            fail: function (res) {
                console.log(222, res);
            }
        })
    },
    callPhone() {
        let arr = []
        this.data.phonelist.forEach((ele, index) => {
            arr.push(ele.phone + '-' + ele.name)
        })
        wx.showActionSheet({
            itemList: arr,
            success: (res) => {
                this.dybbAdfn(0, 0, 1)
                console.log(this.data.phonelist[res.tapIndex].phone)
                this.callPhone1(this.data.phonelist[res.tapIndex].phone + '')
            },
            fail(res) {
                console.log(res.errMsg)
            }
        })
    }
});